package pers.cz.chat.filter;

import io.netty.channel.Channel;
import pers.cz.chat.constants.JefClolorEnum;
import pers.cz.chat.utils.LogUtils;
import pers.cz.netty.filter.FilterHandler;
import pers.cz.netty.filter.FilterHandlerContext;
import pers.cz.netty.protocal.Message;
import pers.cz.netty.protocal.MsgType;
import pers.cz.netty.util.ContextHolder;

/**
 * @version 1.0
 * @description: 通用消息拦截器
 * @author: ChengZhi 0336
 * @create: 2025-01-23 16:57
 **/
public class MessageFilter implements FilterHandler<Message, Channel> {

	@Override
	public boolean approve(Message message, Channel obj, FilterHandlerContext<Message,Channel> handlerContext) {

		if (MsgType.DATA.equals(message.getMsgType()) && !"1".equals(ContextHolder.getRequestContext().get("loginType"))) {
			LogUtils.print(JefClolorEnum.YELLOW,"您还未登录，请登录后重试！");
			return true;
		}
		return handlerContext.doFilter(message, obj);
	}
}
